import { Table, Space, Button } from "antd";
import { memo, useEffect } from "react";
import { useState } from "react";

function MTable({ dataSource, columns, total, getData }) {
  // console.log(dataSource, columns);
  let [params, setParams] = useState({
    page: 1,
    limit: 10,
    title: "",
  })
  let id = null
  dataSource[0]?.id ? id = "id" : id = "_id"
  useEffect(() => {
    getData(params)
  }, [params])
  return (
    <>
      <Table rowKey={id} dataSource={dataSource} columns={columns} pagination={{
        total,
        current: params.page,
        pageSize: params.limit,
        onChange: (page, pageSize) => {
          setParams({
            ...params,
            page,
            pageSize,
          })
        }
      }}></Table>
    </>
  );
}

export default memo(MTable);